package com.example.layoutmodule;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ListViewActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view);

        List<Map<String,Object>> data = new ArrayList<>();
        Map<String,Object> map = new HashMap<>();
        map.put("icon", android.R.drawable.alert_light_frame);
        map.put("name","name---1");
        map.put("content","content---1");
        data.add(map);
        map.put("icon", android.R.drawable.arrow_down_float);
        map.put("name","name---2");
        map.put("content","content---2");
        data.add(map);
        map.put("icon", android.R.drawable.bottom_bar);
        map.put("name","name---3");
        map.put("content","content---3");
        data.add(map);
        map.put("icon", android.R.drawable.alert_light_frame);
        map.put("name","name---1");
        map.put("content","content---1");
        data.add(map);
        map.put("icon", android.R.drawable.arrow_down_float);
        map.put("name","name---1");
        map.put("content","content---1");
        data.add(map);
        map.put("icon", android.R.drawable.bottom_bar);
        map.put("name","name---1");
        map.put("content","content---1");
        data.add(map);
        map.put("icon", android.R.drawable.alert_light_frame);
        map.put("name","name---1");
        map.put("content","content---1");
        data.add(map);
        map.put("icon", android.R.drawable.arrow_down_float);
        map.put("name","name---1");
        map.put("content","content---1");
        data.add(map);
        map.put("icon", android.R.drawable.bottom_bar);
        map.put("name","name---3");
        map.put("content","content---3");
        data.add(map);

        //map对象中的key的数组，用于得到对应的value
        String[] from = {"icon","name","content"};
        //Item布局文件中的子View的数组
        int[] to = {R.id.iv_item_icon,R.id.tv_item_name,R.id.tv_item_content};

        SimpleAdapter adapter = new SimpleAdapter(this,data,R.layout.item_simple_adapter,from,to);
        ((ListView)findViewById(R.id.lv_main)).setAdapter(adapter);
    }
}